<template>
  <div style="width: 100%">
    <div id="deawer">
      <v-tableTitle
        :btnConfig="btnConfig"
        @cancel="cancel"
        @save="save"
      ></v-tableTitle>
      <div class="detailBox">
        <v-detail ref="detail"></v-detail>
      </div>
    </div>
  </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";
import config from "../Config"
import tableTitle from "@/components/commons/TableTitle";
import detail from "../details/Detail"
import bus from "../../../../../bus/bus";

export default {
  name: "",
  mixins: [baseMixin, skipMixin, config],
  data () {
    return {
      newFlag: false,
      routeData: {}
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.save'), certigier: this.saveStatus||!this.btnPermNameList.includes('WM040403'), invalid: "save" },
        { label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM040404'), invalid: "cancel" },
      ]
    }
  },
  created () {
  },
  methods: {

    //保存按钮
    async save () {
      let detail = this.$refs.detail.detailData;
      if (!detail.printername) {
        this.$message.error(this.$tj('manage.printername','app.emptyMes'));
        return
      }
      if (this.newFlag) {
        this.$api.post(`/insertReportprinter`, detail).then(res => {
          
            this.$message.success(res.returnMgr)
            this.cancel()
          
        })
      } else {
        this.$api.post(`/updateReportprinter`, detail).then(res => {
          
            this.$message.success(res.returnMgr)
            this.cancel()
          
        })
      }

    },
    //弹框取消
    cancel () {
      setTimeout(() => {
        this.$router.push({ name: 'reportprinter' });
      }, 500);
    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.routeData = data.routeData;
      this.newFlag = data.newFlag;
    } else {
      this.routeData = this.$store.state.routeData;
      this.newFlag = this.$store.state.newFlag;
    }

  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    "v-detail": detail,
  }
}
</script>

<style scoped>
</style>
